package com.sqoq.downloader3.retrofit;

import androidx.annotation.NonNull;


import java.io.IOException;
import java.util.HashMap;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class HeaderInterceptor implements Interceptor {
    HeaderGetter headerGetter;

    public HeaderInterceptor(HeaderGetter headerGetter) {
        this.headerGetter = headerGetter;
    }

    @NonNull
    @Override
    public Response intercept(@NonNull Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        HashMap<String, String> headerParameters = headerGetter.getHeader();
        for (String key : headerParameters.keySet()) {
            builder.addHeader(key, headerParameters.get(key));
        }
        return chain.proceed(builder.build());
    }
}

